<template>
  <div class="subscribeList">
    <el-card class="cardBox">
      <el-form class="s_form" :inline="true">
        <div class="left">
          <el-form-item>
            <div class="cardName">预约列表</div>
          </el-form-item>
        </div>
        <div class="right">
          <el-form-item>
            <el-input size="small" v-model="dataForm.customerName" placeholder="请输入关键字" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="small" @click="getDataList">查询</el-button>
          </el-form-item>
        </div>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border :height="tabHeight">
        <el-table-column v-for="row in headerList" :key="row.key" :prop="row.key" :min-width="row.width"
          :label="row.label" show-overflow-tooltip header-align="center" align="center"></el-table-column>
      </el-table>
      <el-pagination :current-page.sync="curPage" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataListLoading: false,
      dataForm: {
        customerName: ''
      },
      dataList: [],
      // 资料列表字段
      headerList: [{
        key: 'customerName',
        label: '预约客户',
        width: '150'
      },
      {
        key: 'customerIphone',
        label: '客户联系电话',
        width: '150'
      },
      {
        key: 'carNumber',
        label: '预约车编号',
        width: '150'
      },
      {
        key: 'carModel',
        label: '预约车型',
        width: '150'
      },
      {
        key: 'appointmentDate',
        label: '预约时间',
        width: '100'
      }],
      tabHeight: '600',
      // 分页
      curPage: 1,
      total: 0,
      limit: 10
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.tabHeight = this.$getClientHeight() - 300 + 'px'
    })
  },
  activated () {
    this.getDataList()
  },
  methods: {
    // 获取数据
    getDataList () {
      this.dataListLoading = true
      this.$http.get('/carcustomerinfo/list', {
        params: {
          limit: this.limit,
          page: this.curPage,
          ...this.dataForm
        }
      }).then(({ data: res }) => {
        let { code, msg, page } = res
        console.log(code, msg, page)
        this.dataList = []
        this.total = 0
        if (code === 0 && page) {
          let { list, total } = page
          this.dataList = list && list.length ? list : []
          this.total = total
          this.dataListLoading = false
        }
        if (code !== 0) {
          this.$message.error(msg)
        }
        this.dataListLoading = false
      })
    },
    // 切换每页数量
    pageSizeChangeHandle (size) {
      console.log(size)
      this.limit = size
      this.curPage = 1
      this.getDataList()
    },
    // 切换页
    pageCurrentChangeHandle (curPage) {
      this.curPage = curPage
      this.getDataList()
    }
  }
}
</script>

<style lang="scss">
.subscribeList {
  padding: 20px;
  .cardBox {
    width: 100%;
    min-width: 1100px;
    background-color: rgba(255, 255, 255, 1);
    margin-top: 15px;
    .s_form {
      display: flex;
      justify-content: space-between;
      .cardName {
        font-weight: bold;
        font-size: 18px;
      }
      .s_input {
        width: 100px;
      }
    }
  }
}
</style>
